package com.liufeng.test.spring.config;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletRegistration;

public class WebAppInitializer
        extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class<?>[]{RootConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class<?>[]{WebConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }


    /**
     * 上传文件的配置方法
     * @param dynamic 上传文件配置
     */
    @Override
    protected void customizeRegistration(ServletRegistration.Dynamic dynamic) {
        //文件存储路径，临时
        String filePath = "/temp/uploads";
        //5M
        Long singleMax = (long) ( 5*Math.pow(2,20));
        //10M
        Long totalMax = (long) ( 10*Math.pow(2,20));

        dynamic.setMultipartConfig(new MultipartConfigElement(filePath,singleMax,totalMax,0));

    }
}
